///////////////////////////////////////////////////////////////////////
//
//  File				:	pod.h
//  Classes				:	CPod
//  Description			:	Da implementation
//
////////////////////////////////////////////////////////////////////////
#include "pod.h"

// Encapsulates a content type
typedef enum {
	TYPE_MESH = 1,
	TYPE_MATERIAL,
	TYPE_TEXTURE,
	TYPE_LIGHT,
	TYPE_CAMERA,
	TYPE_SKELETON,
	TYPE_ANIMATION,
	TYPE_CHARACTER,
	TYPE_REFERENCE
} EContentType;

///////////////////////////////////////////////////////////////////////
// Class				:	CPod
// Method				:	CPod
// Description			:	Ctor
// Comments				:
CPod::CPod(const ::POD::Pod &p,QWidget *parent) : QWidget(parent), pod(p) {

	// Setup the user interface
	setupUi(this);

	// We're good to be deleted on close
	QWidget::setAttribute(Qt::WA_DeleteOnClose);

	// We use this macro to populate our table of contents
#define	populate(__class,__name,__header,__type)	\
	if (pod.__name##_size() > 0) {					\
		QTreeWidgetItem	*__name	=	new QTreeWidgetItem(contents,QStringList(__header));	\
		for (int i=0;i<pod.__name##_size();++i) {	\
			const ::POD::__class	&item	=	pod.__name(i);	\
			QTreeWidgetItem	*titem	=	new QTreeWidgetItem(__name,QStringList(	(item.has_name() ? QString::fromStdString(item.name()) : QString::number(i))),__type);	\
			Q_UNUSED(titem);						\
		}											\
	}

	// Look what we have in the POD file and populate the contents
	populate(Texture,textures,"Textures",TYPE_TEXTURE);
	populate(Mesh,meshes,"Meshes",TYPE_MESH);
	populate(Material,materials,"Materials",TYPE_MATERIAL);
	populate(Light,lights,"Lights",TYPE_LIGHT);
	populate(Camera,cameras,"Cameras",TYPE_CAMERA);
	populate(Animation,animations,"Animations",TYPE_ANIMATION);
	populate(Skeleton,skeletons,"Skeletons",TYPE_SKELETON);
	populate(Character,characters,"Characters",TYPE_CHARACTER);
	populate(Reference,references,"References",TYPE_REFERENCE);

	// We're done with this macro
#undef populate
}

///////////////////////////////////////////////////////////////////////
// Class				:	CPod
// Method				:	~CPod
// Description			:	Dtor
// Comments				:
CPod::~CPod() {
}

///////////////////////////////////////////////////////////////////////
// Class				:	CPod
// Method				:	on_contents_itemDoubleClicked
// Description			:	An item is double clicked, raise it
// Comments				:
void	CPod::on_contents_itemDoubleClicked(const QTreeWidgetItem *item,int column) {
	Q_UNUSED(column);

	// Figure out the type of the content
	switch(item->type()) {
		case TYPE_MESH:
			break;
		case TYPE_MATERIAL:
			break;
		case TYPE_TEXTURE:
			break;
		case TYPE_LIGHT:
			break;
		case TYPE_CAMERA:
			break;
		case TYPE_SKELETON:
			break;
		case TYPE_ANIMATION:
			break;
		case TYPE_CHARACTER:
			break;
		case TYPE_REFERENCE:
			break;
		default:
			break;
	}
}
